module.exports = class AsyncSeriesHook {
  constructor(args){
      this.tasks = []
  }
  tapAsync(name,task){
   this.tasks.push(task)
  }
  callAsync(...args){
   const finalCallback = args.pop()
   let index = 0;
   const next = ()=> {
    if(index === this.tasks.length) return finalCallback()
    this.tasks[index++](...args,next)
   }
   next()
  }
  tapPromise(name,task){
   this.tasks.push(task)
  }
  promise(...args){
    const [first,...others] = this.tasks
    return others.reduce((p,n)=>{
      return p.then(()=>n(...args))
    },first(...args))
  }
}
